package concurrency;

/**
 * 定义任务
 * 2018年 09月 13日 星期四
 *
 * @author fireway
 */
public class LiftOff implements Runnable {
    protected int mCountDown = 10;

    private static int sTaskCount = 0;

    /**
     * 标识符mId可以用来区分任务的多个实例，它是final的，因为它一旦被初始化之后就不希望再被修改。
     */
    private final int mId = sTaskCount++;

    public LiftOff() {

    }

    public LiftOff(int countDown) {
        mCountDown = countDown;
    }

    public String status() {
        String msg = mCountDown > 0 ? "" + mCountDown : "LiftOff";
        return "#" + mId + "(" + msg + "), ";
    }

    @Override
    public void run() {
        while (mCountDown-- > 0) {
            System.out.print(status());
            Thread.yield();
        }
    }

    public static void main(String[] args) {
        LiftOff launch = new LiftOff();
        launch.run();
    }
}
